<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" th:with="title='用户管理',active='user'">
<header th:replace="admin/header::headerFragment(${title},${active})"></header>
<body class="fixed-left">
<div id="wrapper">
    <div th:replace="admin/header::header-body"></div>
    <div class="content-page">
        <div class="content">
            <div class="container">
                <div class="row">
                    <div class="col-sm-6">
                        <h4 class="page-title">用户管理</h4>
                    </div>
                    <div class="col-sm-6">
                        <form id="searchForm" class="form-inline" role="form" novalidate="novalidate"
                              th:action="@{'/admin/users'}">
                            <div class="form-group">
                                <input type="text" id="userName" name="userName" class="form-control" style="width:300px"
                                       placeholder="请输入用户名" th:value="${userName}"/>
                            </div>

                            <button type="submit" class="btn btn-success waves-effect waves-light m-l-10">搜索</button>
                            <div class="form-group pull-right">
                                <a th:href="@{/admin/users/new}" class="btn btn-success waves-effect waves-light m-b-5">添加新用户</a>
                            </div>
                        </form>

                    </div>
                    <!--<div class="col-sm-3">
                        <div class="pull-right">
                            <a th:href="@{/admin/users/new}" class="btn btn-success waves-effect waves-light m-b-5">添加新用户</a>
                        </div>
                    </div>-->
                    <div class="col-md-12">
                        <table class="table table-striped table-bordered">
                            <thead>
                            <tr>
                                <th width="35%">登录名</th>
                                <th width="15%">邮箱</th>
                                <th>用户名</th>
                                <th>创建时间</th>
                                <th width="8%">是否激活</th>
                                <th>用户组</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <th:block th:each="user : ${users.list}">
                                <tr th:cid="${user.uid}">
                                    <td>
                                        <a th:href="@{'/admin/users/'+${user.uid}}" th:text="${user.username}"></a>
                                    </td>
                                    <td><th:block th:text="${user.email}"/></td>
                                    <td><th:block th:text="${user.screenName}"/></td>
                                    <td><th:block th:text="${commons.fmtdate(user.created, 'yyyy-MM-dd HH:mm:ss')}"/></td>
                                    <td>
                                        <th:block th:if="${user.activated == 1}">
                                            <span class="label label-success">已激活</span>
                                        </th:block>
                                       <th:block th:if="${user.activated == 0}">
                                           <span class="label label-default">未激活</span>
                                       </th:block>
                                    </td>
                                    <td><th:block th:text="${user.groupName}"/></td>
                                    <td>
                                        <a th:href="@{'/admin/users/'+${user.uid}}"
                                           class="btn btn-primary btn-sm waves-effect waves-light m-b-5"><i
                                                class="fa fa-edit"></i> <span>编辑</span></a>
                                        <a href="javascript:void(0)" th:onclick="'delUser('+${user.uid}+');'"
                                           class="btn btn-danger btn-sm waves-effect waves-light m-b-5"><i
                                                class="fa fa-trash-o"></i> <span>删除</span></a>
                                    </td>
                                </tr>
                            </th:block>

                            </tbody>
                        </table>
                        <div th:replace="comm/macros :: pageAdminNav(${users})"></div>
                    </div>
                </div>
                <div th:replace="admin/footer :: footer-content"></div>
            </div>
        </div>
    </div>
</div>
<div th:replace="admin/footer :: footer"></div>
<script type="text/javascript">
    /*<![CDATA[*/
    var tale = new $.tale();
    function delUser(uid) {
        tale.alertConfirm({
            title:'确定删除该文章吗?',
            then: function () {
                tale.post({
                    url : getContextPath() + '/admin/users/chageActivate',
                    data: {activated: 0,uid: uid},
                    success: function (result) {
                        if(result && result.success){
                            tale.alertOkAndReload('用户删除成功');
                        } else {
                            tale.alertError(result.msg || '用户删除失败');
                        }
                    }
                });
            }
        });
    }
    /*]]>*/
</script>
</body>
</html>